home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 4 / Meeting Pearls Vol. IV (1996)(GTI - Schatztruhe)[!].iso / Pearls / dev / ASM-Src / NewStartup / Startup.s < prev    next >
Text File  |  1996-06-06  |  12KB  |  458 lines

  1. *****************************************************************************
  2. *    "Startup.asm"
  3. *
  4. *    $VER: Startup_asm 3.8 (06.06.96)
  5. *
  6. *    Copyright © 1995,1996 by Kenneth C. Nilsen/Digital Surface
  7. *    This source is freely distributable.
  8. *
  9. *    For instructions read the Startup_Asm.doc or the Startup_example.s
  10. *
  11. *SUMMARY:
  12. *
  13. *StartSkip    =    0 or 1 (0 = wb/cli, 1=cli only (eg. from AsmOne))
  14. *Processor    =    0 or 680x0
  15. *MathProc    =    0 or 6888x/68040/68060
  16. *
  17. *Init:    Version        <"PrgName ver.rev (date)">        (obsolete)
  18. *    TaskName    <"new task name in quotes">        (opt)
  19. *    TaskPri        <priority>                (opt)
  20. *    DefLib        <libname wo/.library>,<version>        (opt)
  21. *    DefEnd        ;must end the "Init:" section ALWAYS!    (required!)
  22. *
  23. *Start:    LibBase        <libname wo/.library>            (opt)
  24. *    StartFrom    = 0 (CLI) or <>0 (WB) in D0        (opt)
  25. *    TaskPointer    = pointer to taskstructure  (D0)    (opt)
  26. *    NextArg        = pointer to next argument or 0  (D0)    (opt)
  27. *    Return        <return value> (with RTS)        (recommended)
  28. *
  29. *****************************************************************************
  30.  
  31. zyxMax    = 17    ;max no. of libraries for AllocMem()
  32. zyxBufZ    = 308    ;size of format buffer in bytes for AllocMem()
  33.  
  34. ; Default settings will require 512 bytes allocated memory.
  35. ; The buffer is independent of this header.
  36.  
  37. *-----------------------------------------------------------------------------*
  38. * Macros for Startup.asm
  39. *-----------------------------------------------------------------------------*
  40.  
  41. Return:    Macro
  42.     moveq    #\1,d0    ;* if you use rtn code >127, change to "move.l"
  43.     rts                ;exit our program
  44.     EndM
  45.  
  46. DefLib:    Macro
  47.  
  48.     lea    \1NamX(pc),a1        ;make exclusive library namelabel
  49.     move.l    a1,(a5)+        ;put name into our buffer (if print)
  50.     move.l    a1,zyxNx        ;store name in local label
  51.     moveq    #\2,d0        ;if you use ver >127, change this to "move.l"
  52.     move.l    d0,(a5)+        ;store version in our buffer
  53.     move.l    d0,zyxVx        ;store version in local label
  54.     jsr    -552(a6)        ;try open library
  55.     move.l    d0,(a5)+        ;store result in our buffer
  56.  
  57.     move.l    d0,\1basX        ;store result in global label
  58.     bne.b    \1zyx            ;if <>0 then ok
  59.  
  60.     bsr.w    zyxLibR            ;print error message
  61.     bra.b    \1zyx            ;go on...
  62.  
  63. \1basX:    dc.l    0
  64. \1NamX:    dc.b    "\1.library",0        ;library name macro
  65.     even
  66. \1zyx:
  67.     EndM
  68.  
  69. DefEnd:    Macro
  70.     move.l    #-1,(a5)        ;this terminate our library list
  71.     rts
  72.     EndM
  73.  
  74. LibBase:    Macro
  75.     move.l    \1basX(pc),a6        ;get library base with exclusive name
  76.     EndM
  77.  
  78. TaskName:    Macro
  79.  
  80.     move.l    $4.w,a6            ;exec base
  81.     jsr    -132(a6)        ;Forbid()
  82.     move.l    zyxTask(pc),a0        ;get stored task pointer to our task
  83.     move.l    #.TaskN,10(a0)        ;get ptr. to new name and store
  84.     jsr    -138(a6)        ;Permit()
  85.     bra.b    .zyxTsk            ;go on...
  86.  
  87. .TaskN:    dc.b    \1            ;task name macro
  88.     dc.b    0            ;null terminate
  89.     even
  90. .zyxTsk:
  91.     EndM
  92.  
  93. TaskPri:    Macro
  94.     move.l    $4.w,a6            ;execbase
  95.     move.l    zyxTask(pc),a1        ;get stored task pointer
  96.     moveq    #\1,d0            ;get new task priority
  97.     jsr    -300(a6)        ;SetTaskPri()
  98.     EndM
  99.  
  100. TaskPointer:    Macro
  101.     move.l    zyxTask(pc),d0        ;give pointer to task in d0
  102.     EndM
  103.  
  104. StartFrom:    Macro
  105.     move.l    RtnMess(pc),d0        ;if started from WB, d0<>0
  106.     EndM
  107.  
  108.  
  109. NextArg:    Macro
  110.     move.l    zyxArgP(pc),d0        ;get address to argument string
  111.     beq.b    *+8            ;none? (from WB) then skip
  112.     move.l    d0,a0            ;use pointer
  113.     bsr.w    zyxGArg            ;go to our internal routine
  114.     move.l    a0,zyxArgP        ;update argument pointer
  115.     tst.l    d0            ;set/unset Z flag
  116.     EndM
  117.  
  118. ;*! Obsolete: Don't use the Version macro from Startup.asm 3.5+ !* :
  119.  
  120. Version:    Macro
  121.     bra.s    .zyxVer
  122.     dc.b    "$VER: "
  123.     dc.b    "\1",0
  124.     even
  125. .zyxVer:
  126.     EndM
  127.  
  128. *-----------------------------------------------------------------------------*
  129. * MAIN routine:
  130. *-----------------------------------------------------------------------------*
  131.  
  132. GoZYX:    move.l    a0,-(sp)        ;store argument pointer
  133.  
  134.     move.l    d0,zyxArgL        ;store length of arg. string
  135.     move.l    a0,zyxArgP        ;store arg. pointer in internal label
  136.  
  137.     move.l    $4.w,a6            ;exec base
  138.     move.l    a6,execbasX        ;allow "LibBase exec"
  139.  
  140.     move.l    #zyxBufZ,d0        ;set buffer size
  141.     moveq    #1,d1            ;requirements (public, clear)
  142.     jsr    -198(a6)        ;AllocMem()
  143.     move.l    d0,zyxBuff        ;store result in label
  144.     beq.w    .DOS            ;Null? then exit
  145.  
  146.     sub.l    a1,a1            ;a1=0 (this task)
  147.     jsr    -294(a6)        ;FindTask()
  148.     move.l    d0,a4            ;copy result
  149.     move.l    d0,zyxTask        ;store for internal use
  150.  
  151.     tst.l    172(a4)            ;where we started from (wb/cli)
  152.     bne.b    .chkPro            ;<>0 then cli
  153.  
  154.     moveq    #StartSkip,d0        ;check if we wanne skip (eg. AsmOne)
  155.     bne.b    .chkPro            ;yepp, then skip
  156.     lea    92(a4),a0        ;get message port address
  157.     jsr    -384(a6)        ;WaitPort()
  158.     lea    92(a4),a0        ;get message port address
  159.     jsr    -372(a6)        ;GetMsg()
  160.     move.l    d0,RtnMess        ;store message pointer in label
  161.  
  162. .chkPro:
  163.     move.w    296(a6),d5        ;AttnFlags in execbase
  164.  
  165.     move.l    #Processor,d7        ;processor we want
  166.     beq.w    .ProOk            ;null? then any will do, skip this part
  167.     cmp.w    #60,d7
  168.     ble.w    .nxPro1            ;then skip too...
  169.     sub.l    #68000,d7
  170.     beq.w    .ProOk
  171.  
  172. .nxPro1:
  173.     cmp.b    #10,d7            ;68010?
  174.     bne.b    .nxPro2            ;no, check next
  175.     and.b    #$cf,d5            ;check bits
  176.     bne.w    .ProOk            ;we got a 68010 or higher
  177.     bra.w    .ProErr            ;we got lower, we can't start...
  178.  
  179. .nxPro2:
  180.     cmp.b    #20,d7            ;same as above, just higher processor
  181.     bne.b    .nxPro3
  182.     and.b    #$ce,d5
  183.     bne.w    .ProOk
  184.     bra.b    .ProErr
  185.  
  186. .nxPro3:
  187.     cmp.b    #30,d7
  188.     bne.b    .nxPro4
  189.     and.b    #$cc,d5
  190.     bne.b    .ProOk
  191.     bra.b    .ProErr
  192.  
  193. .nxPro4:
  194.     cmp.b    #40,d7
  195.     bne.b    .nxPro5
  196.     and.b    #$c8,d5
  197.     bne.b    .ProOk
  198.     bra.b    .ProErr
  199.  
  200. .nxPro5:
  201.     cmp.b    #60,d7            ;we want a 68060 (yes, we do :) )
  202.     bne.b    .ProWho            ;not? then I dont know about any higher
  203.     btst    #7,d5            ;test if it is a 68060 we're using
  204.     beq.b    .ProErr            ;nope
  205.     btst    #6,d5            ;are you sure?
  206.     bne.b    .ProOk            ;yepp, continue
  207.     bra.b    .ProErr            ;not a 060, print error message
  208.  
  209. .ProWho:
  210.     lea    ProcWho(pc),a0        ;unknown processor required, print
  211.     move.l    #Processor,ProcNum    ;print message about it...
  212.     lea    ProcNum(pc),a1
  213.     bsr.w    zyxPrt
  214.     bra.w    .End
  215.  
  216. .ProErr:
  217.     st    zyxLR
  218.     lea    ProcErr(pc),a0        ;we don't got the processor required
  219.     add.l    #68000,d7
  220.     move.l    d7,ProcNum        ;message about it.
  221.     lea    ProcNum(pc),a1
  222.     bsr.w    zyxPrt            ;jump to our cli print routine
  223.  
  224. .ProOk:    move.l    #MathProc,d7        ;time to check for math-co-processor
  225.     beq.w    .MathOk            ;null? then any will do...
  226.     sub.l    #68000,d7
  227.  
  228.     cmp.w    #881,d7            ;a 68881?
  229.     bne.b    .Math2            ;no check next
  230.     and.b    #$70,d5            ;check flags
  231.     bne.b    .MathOk            ;we got it
  232.     bra.b    .MathEr            ;sorry...
  233.  
  234. .Math2:    cmp.w    #882,d7            ;same as above
  235.     bne.b    .Math3
  236.     and.b    #$60,d5
  237.     bne.b    .MathOk
  238.     bra.b    .MathEr
  239.  
  240. .Math3:    cmp.b    #60,d7
  241.     beq.b    .m60ok
  242.     cmp.b    #40,d7            ;we have 040/060 with FPU not 881/882
  243.     bne.b    .MathEr            ;unknown FPU if any else...
  244. .m60ok    btst    #6,d5            ;we got it?
  245.     bne.b    .MathOk            ;yepp, continue
  246.  
  247. .MathEr:
  248.     st    zyxLR
  249.     lea    ProcErr(pc),a0        ;print error message...
  250.     move.l    #MathProc,ProcNum    ;number data
  251.     lea    ProcNum(pc),a1
  252.     bsr.w    zyxPrt
  253.  
  254. .MathOk:
  255.     bsr.w    zyxLibO            ;oki, open our libraries
  256.  
  257.     tst.b    zyxLR            ;any errors?
  258.     bne.b    .noShow            ;yepp, don't start
  259.  
  260.     move.l    zyxArgP(pc),a0        ;get arg. pointer
  261.     move.l    zyxArgL(pc),d0        ;get arg. length
  262.  
  263.     bsr.w    Start            ;! start main program !
  264.     move.l    d0,zyxVal        ;store return code
  265.  
  266. .noShow:
  267.     bsr.w    zyxLibC            ;close libraries if any
  268.  
  269. .End:    move.l    zyxBuff(pc),d0        ;get pointer to our buffer
  270.     beq.b    .noBuff            ;no buffer?!?
  271.     move.l    d0,a1            ;copy pointer
  272.     move.l    #zyxBufZ,d0        ;length of buffer
  273.     jsr    -210(a6)        ;FreeMem()
  274.  
  275. .noBuff:
  276.     tst.l    RtnMess            ;from WB?
  277.     beq.w    .DOS            ;nope, from CLI
  278.  
  279.     jsr    -132(a6)        ;Forbid()
  280.     move.l    RtnMess(pc),a1        ;put message in a1
  281. ;    jsr    -138(a6)        ;Permit()
  282.     jsr    -378(a6)        ;ReplyMsg()
  283.  
  284. .DOS:    move.l    (sp)+,a0        ;restore stack, put arg. pointer back
  285.     move.l    zyxVal(pc),d0        ;set return code
  286.     rts                ;BYE! :)
  287.  
  288. zyxDo:    move.b    d0,(a3)+        ;for RawDoFmt(), process routine
  289.     rts
  290.  
  291. zyxPrt:    movem.l    d0-a6,-(sp)        ;store regs. on stack
  292.  
  293.     lea    zyxDo(pc),a2        ;process
  294.     move.l    zyxBuff(pc),a3        ;format buffer
  295.     jsr    -522(a6)        ;RawDoFmt()
  296.  
  297.     moveq    #0,d0            ;any version
  298.     lea    zyxDos(pc),a1        ;ptr. to dos.library name
  299.     jsr    -552(a6)        ;OpenLibrary()
  300.     tst.l    d0            ;failed?
  301.     beq.b    .exit            ;jepp, exit
  302.     move.l    d0,a6            ;use dosbase
  303.  
  304.     jsr    -60(a6)            ;Output()
  305.     move.l    d0,d1            ;copy, set Z, failed?
  306.     beq.b    .clDos            ;no output -> close dos.library
  307.  
  308.     move.l    zyxBuff(pc),d2        ;get ptr. to our buffer
  309.     move.l    d2,a0            ;copy pointer
  310.     moveq    #0,d3            ;clear D3 (length of buffer)
  311. .count:    addq    #1,d3            ;add 1 to length of line
  312.     tst.b    (a0)+            ;get one char
  313.     bne.b    .count            ;null? yepp, found end...
  314.  
  315.     subq    #1,d3            ;exclude last sign (null)
  316.  
  317.     jsr    -48(a6)            ;print buffer to output handler (CLI)
  318.  
  319. .clDos:    lea    (a6),a1            ;copy dosbase to a1
  320.     move.l    $4.w,a6            ;get exebase
  321.     jsr    -414(a6)        ;CloseLibrary()
  322.  
  323. .exit:    movem.l    (sp)+,d0-a6        ;restore stack
  324.     rts                ;return
  325.  
  326. zyxLibO:
  327.     move.l    #4*3*zyxMax,d0        ;library buffer size 12*zyxMax (192)
  328.     moveq    #1,d1            ;any mem
  329.     jsr    -198(a6)        ;AllocMem()
  330.     move.l    d0,zyxMem        ;store result
  331.     beq.b    .memErr            ;null? then error
  332.  
  333.     move.l    d0,a5            ;use buffer
  334.     bsr.w    Init            ;jump to init section (see macros)
  335.  
  336.     rts                ;done
  337.  
  338. .memErr:
  339.     lea    zyxFR(pc),a0        ;get format text
  340.     lea    zyxMeR(pc),a1        ;get input string
  341.  
  342.     bsr.w    zyxPrt            ;print message about low memory
  343.  
  344.     st    zyxLR            ;failed, don't start main program
  345.     rts                ;return
  346.  
  347. zyxLibC:
  348.     move.l    $4.w,a6            ;execbase
  349.  
  350.     move.l    zyxMem(pc),d0        ;library buffer
  351.     beq.w    .noLibs            ;null? then no libraries
  352.     move.l    d0,a5            ;use pointer
  353.  
  354. .loop:    cmp.l    #-1,(a5)        ;end?
  355.     beq.b    .clEnd            ;yepp, then done!
  356.     move.l    8(a5),d0        ;get library base
  357.     beq.b    .noCl            ;null? then this lib. failed to open
  358.     move.l    d0,a1            ;use base
  359.     jsr    -414(a6)        ;CloseLibrary()
  360. .noCl:    lea    12(a5),a5        ;get next library base
  361.     bra.b    .loop            ;continue
  362.  
  363. .clEnd:    move.l    zyxMem(pc),a1        ;get lib. buffer pointer
  364.     move.l    #4*3*zyxMax,d0        ;size
  365.     jsr    -210(a6)        ;FreeMem()
  366.  
  367. .noLibs:
  368.     rts
  369.  
  370. zyxLibR:
  371.     st    zyxLR            ;if any errors, set error flag
  372.  
  373.     lea    zyxLib(pc),a0        ;pointer to format text
  374.     lea    zyxNx(pc),a1        ;pointer to format data
  375.     bsr.w    zyxPrt            ;print library name
  376.  
  377.     rts                ;return
  378.  
  379. zyxGArg:
  380.     move.b    (a0)+,d0        ;get a char from arg. line
  381.     beq.w    .end            ;null? end of line
  382.     cmp.b    #10,d0            ;linefeed?
  383.     beq.w    .end            ;end of line
  384.     cmp.b    #9,d0            ;tab?
  385.     beq.b    zyxGArg            ;get another char
  386.     cmp.b    #32,d0            ;space?
  387.     beq.b    zyxGArg            ;get another char
  388.  
  389.     move.l    zyxBuff(pc),a1        ;our text buffer
  390.     lea    -1(a0),a0        ;go back one byte on arg. line
  391. .copy:    move.b    (a0)+,d0        ;copy char to d0
  392.     beq.b    .stop            ;null? then stop copy
  393.     cmp.b    #10,d0            ;linefeed?
  394.     beq.b    .stop            ;stop copy
  395.     cmp.b    #32,d0            ;space?
  396.     beq.b    .eol            ;then this arg. is done
  397. .cont:    cmp.b    #'*',d0            ;asterix?
  398.     beq.b    .chkSpc            ;check for special functions
  399.     cmp.b    #'"',d0            ;quote?
  400.     beq.b    .toggle            ;toggle copy mode
  401. .noChk:    move.b    d0,(a1)+        ;copy passed char to our buffer
  402. .cont2:    bra.b    .copy            ;continue copy
  403.  
  404. .chkSpc:
  405.     cmp.b    #'"',(a0)        ;a quote want to be used?
  406.     bne.b    .chk2            ;no, check for a linefeed then...
  407.     move.b    #'"',(a1)+        ;copy a quote to our buffer
  408.     lea    1(a0),a0        ;skip one byte (2(*")->1("))
  409.     bra.b    .copy            ;continue copy argument
  410. .chk2:    cmp.b    #'n',(a0)        ;a linefeed?
  411.     bne.b    .noChk            ;nope, skip special funcs.
  412.     move.b    #10,(a1)+        ;copy a linefeed to our buffer
  413.     lea    1(a0),a0        ;make 2 -> 1
  414.     bra.b    .copy            ;continue copy
  415.  
  416. .toggle:
  417.     tst.b    zyxQ            ;already toggled?
  418.     beq.b    .set            ;nope, then toggle
  419.     sf    zyxQ            ;re toggle
  420.     bra.b    .stop            ;end of argument
  421. .set:    st    zyxQ            ;toggle so we can use space in arg.
  422.     bra.b    .cont2            ;continue copying argument
  423.  
  424. .eol:    tst.b    zyxQ            ;end of line -> toggled?
  425.     bne.b    .cont            ;jepp, continue
  426.  
  427. .stop:    tst.b    zyxQ            ;toggled?
  428.     bne.b    .end            ;jepp,don't care about this arg (error)
  429.     clr.b    (a1)            ;terminate buffer
  430.     move.l    zyxBuff(pc),d0        ;pointer to extracted argument
  431.     rts                ;return to macro
  432.  
  433. .end:    moveq    #0,d0            ;no more args
  434.     rts                ;return to macro
  435.  
  436. RtnMess:    dc.l    0        ;pointer to WB message
  437. ProcNum:    dc.l    0        ;processor wanted
  438. execbasX:    dc.l    0        ;pointer to execbase
  439. zyxArgL:    dc.l    0        ;argument line length
  440. zyxArgP:    dc.l    0        ;pointer to argument string
  441. zyxVal:        dc.l    0        ;return code
  442. zyxMem:        dc.l    0        ;pointer to library buffer
  443. zyxNx:        dc.l    0        ;temp lib. name
  444. zyxVx:        dc.l    0        ;temp lib. version
  445. zyxTask:    dc.l    0        ;pointer to task structure
  446. zyxBuff:    dc.l    0        ;pointer to string buffer
  447. zyxMeR:        dc.l    zyxMemR        ;pointer to a format string
  448. zyxLR:        dc.b    0        ;error flag
  449. zyxQ:        dc.b    0        ;toggle flag for quotes
  450.  
  451. zyxDos:        dc.b    'dos.library',0
  452. zyxLib:        dc.b    "Can't open %s v. %ld",10,0
  453. zyxMemR:    dc.b    'Low memory!',10,0
  454. zyxFR:        dc.b    '%s',0
  455. ProcWho:    dc.b    'Right! %ld ?',10,0
  456. ProcErr:    dc.b    'Need %ld or better!',10,0
  457.         even
  458.